package com.wbdgj.ui.word_compaign;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.google.gson.internal.LinkedTreeMap;
import com.igexin.sdk.PushManager;
import com.wbdgj.R;
import com.wbdgj.adapter.WordCompaignAdapter;
import com.wbdgj.adapter.WordResultAdapter;
import com.wbdgj.base.BaseApplication;
import com.wbdgj.http.HttpAdapter;
import com.wbdgj.http.OnResponseListener;
import com.wbdgj.model.ResultObjectModel;
import com.wbdgj.ui.coupon.CouponDetailAbleActivity;
import com.wbdgj.ui.login.LoginActivity;
import com.wbdgj.utils.SpKeyUtils;
import com.wbdgj.utils.ToastUtils;
import com.wbdgj.utils.dialog.ConfirmDialog;

import java.text.DecimalFormat;
import java.util.List;

import retrofit2.Call;

public class CouponCompaignDialogResultActivity extends Activity{

    private Context context = this;

    private ListView roomGrid;
    private TextView num;
    private WordResultAdapter wordCompaignAdapter;
    private List<LinkedTreeMap> linkedTreeMaps;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.ui_word_tatter_result_dialog);
        getWindow().getAttributes().width = RelativeLayout.LayoutParams.MATCH_PARENT;
        getWindow().getAttributes().gravity = Gravity.CENTER;
        linkedTreeMaps = BaseApplication.getInstance().getlinkedTreeMapList();
        roomGrid = findViewById(R.id.roomGrid);
        num = findViewById(R.id.num);
        findViewById(R.id.closeImg).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setResult(3);
                finish();
            }
        });

        wordCompaignAdapter = new WordResultAdapter(context, linkedTreeMaps);
        roomGrid.setAdapter(wordCompaignAdapter);
        num.setText("获得"+ linkedTreeMaps.size() +"张优惠券");

        roomGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                DecimalFormat decimalFormat = new DecimalFormat("###################.###########");
                if(!wordCompaignAdapter.hasNoData){
                    startActivity(new Intent(context, CouponDetailAbleActivity.class).putExtra("id", wordCompaignAdapter.getItem(i).get("m_key")+""));
                }
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

    }
}
